package main

import (
	"bufio"
	"fmt"
	"go_test/google/bibao/fb"
	"os"
)
/**
	defer 列表先进后出
	open close
	加锁、解锁
 */
func tryDefer() {
	defer fmt.Println(1)
	defer fmt.Println(2)
	fmt.Println(3)
	panic("error occurred")
	fmt.Println(4)
}

func writeFile(filename string) {
	//自定义error
	//err := errors.New("自定义error")

	file, err := os.Create(filename)
	if err != nil {
		panic(err.Error())
	}
	defer file.Close()
	writer := bufio.NewWriter(file) //读取到缓存
	defer writer.Flush() //导入到文件
	f := fb.Fibonacci()
	for i := 0; i < 10; i++ {
		fmt.Fprintln(writer, f())
	}
}

func main() {
	//tryDefer()
	writeFile("fb1.txt")
}
